#ifndef PAGE_LRU_CACHE_H
#define PAGE_LRU_CACHE_H


#include <string>
#include <list>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <thread>
#include <memory>
#include <thread>
#include <cmath>
#include <tuple>


using std::thread;
using std::pair;
using std::string;
using std::unordered_map;   
using std::vector;
using std::list;
using std::mutex;
using std::shared_ptr;
using std::tuple;

struct KeywordInfo {
    string word; //关键词
    double queryWeight;//输入关键字权重
    double docWeight;//索引库中权重
};




class PageLRUCache {
public:
   static PageLRUCache& getInstance(int capacity=200) {
        static PageLRUCache instance(capacity);
        return instance;
    }

public:
    struct CacheNode {
        string m_key;
        vector<tuple<int, double, vector<KeywordInfo>>> m_values;
    };

public: 
    // 获取缓存中的值
    vector<tuple<int, double, vector<KeywordInfo>>> get(string key);
    // 插入缓存
    void put(string key, vector<tuple<int, double, vector<KeywordInfo>>> values);
    
    PageLRUCache& operator=(const PageLRUCache&) = delete;
    PageLRUCache(const PageLRUCache&) = delete;

private:
    PageLRUCache(int capacity=200);
    ~PageLRUCache();
    mutex _mutex;
    int _capacity;
    // std::shared_ptr<list<CacheNode>> _cache;
    // std::shared_ptr<unordered_map<string, list<CacheNode>::iterator>> _index;
    vector<std::pair<std::shared_ptr<list<CacheNode>>, std::shared_ptr<unordered_map<string, list<CacheNode>::iterator>>>> _cachesum;
};


#endif